/*
 * marketsim-eclipsetrader
 *
 * Copyright (C) 2008-2011 Steve Phelps and John Cartlidge
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 */
/*
 *  (C) Victria Ltd. 2007
 */
package victria.marketsim.ordertype;

import org.apache.log4j.Logger;

import victria.marketsim.core.Order;

/**
 * Sets default minimumOrderSize and maximumOrderSize
 * as a percentage of existing order quantity.
 * 
 * @author sphelps
 *
 */
public class PercentageOrderType implements OrderType {

	static Logger logger = Logger.getLogger(PercentageOrderType.class);
	
	protected float minimumPercentage;
	
	protected float maximumPercentage;
	
	public PercentageOrderType() {
	}
	
	public PercentageOrderType(float minimumPercentage,
			float maximumPercentage) {
		super();
		this.minimumPercentage = minimumPercentage;
		this.maximumPercentage = maximumPercentage;
	}

	public void setDefaultValues(Order currentOrder) {
		int quantity = currentOrder.getQuantity();
		currentOrder.setMinimumOrderSize(percent(quantity, minimumPercentage));
		currentOrder.setMaximumOrderSize(percent(quantity, maximumPercentage));
	}
	
	public static int percent(int quantity, float percentage) {
		return (int) Math.round(quantity * (percentage/100));
	}
	
	public float getMaximumPercentage() {
		return maximumPercentage;
	}
	
	public void setMaximumPercentage(float maximumPercentage) {
		this.maximumPercentage = maximumPercentage;
	}

	public float getMinimumPercentage() {
		return minimumPercentage;
	}

	public void setMinimumPercentage(float minimumPercentage) {
		this.minimumPercentage = minimumPercentage;
	}


}
